package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.Constan;
import service.implement.TimesheetDAO;
import model.Timesheet;

/**
 * Servlet implementation class doaddTimesheet
 */
@WebServlet("/doaddTimesheet")
public class doaddTimesheet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public doaddTimesheet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter pw=response.getWriter();
		String  ma=request.getParameter("employeeid");
		int employeeid=Integer.parseInt(ma);
		String ma1=request.getParameter("projectid");
		int projectid=Integer.parseInt(ma1);
		String date=request.getParameter("date");
		String duration1=request.getParameter("duration");
		int duration=Integer.parseInt(duration1);
		String description=request.getParameter("description");
		String activity=request.getParameter("activity");
		String overtime=request.getParameter("overtime");
		String location=request.getParameter("location");
		int id=java.sql.Types.NULL;
		Timesheet ts=new Timesheet(id,date,duration,description,activity,overtime,location,employeeid,projectid);
		TimesheetDAO dao=new TimesheetDAO();
		if(dao.addTimesheet(ts)==Constan.SER_STATUS_SUCSESS){
			RequestDispatcher rd = request.getRequestDispatcher("listTimesheet.jsp");
			rd.forward(request, response);
		}
		else{
			RequestDispatcher rd = request.getRequestDispatcher("ProjectForm.jsp");
			rd.forward(request, response);
		}
	}

}
